package top.fyxxxx.dbdesign.data;

import top.fyxxxx.dbdesign.dao.DBoperate;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class TaskData implements Comparable<TaskData>{
    private SignInTask task;
    private List<SignInRecord> records;
    private Set<Long> unsignin;
    private int total;
    public TaskData(SignInTask task,List<SignInRecord> records)
    {
        this.task=task;
        this.records=records;
        unsignin=DBoperate.getInstance().getMemberUid(task.getBelongToCid());
        Iterator<Long>it=unsignin.iterator();
        while (it.hasNext()){
            long uid=it.next();
            //剔除管理员
            if((DBoperate.getInstance().getPersonalData(uid,task.getBelongToCid()).getPower()&2)!=0)
                it.remove();
        }
        total=unsignin.size();
        for(SignInRecord record:records){
            unsignin.remove(record.getBelongToUid());
        }
    }
    public List<SignInRecord> getRecords() {
        return records;
    }

    public int getSignInNum(){
        return total-unsignin.size();
    }
    public int getTotal(){
        return total;
    }
    public int getUnSignInNum(){
        return unsignin.size();
    }
    public List<String> getUnSignInNames(){
        List<String>ret=new ArrayList<>();
        for(long uid:unsignin)ret.add(DBoperate.getInstance().getAccountByUid(uid).getName());
        return ret;
    }
    public void setRecords(List<SignInRecord> records) {
        this.records = records;
    }

    public SignInTask getTask() {
        return task;
    }

    public void setTask(SignInTask task) {
        this.task = task;
    }

    @Override
    public int compareTo(TaskData o) {
        return task.compareTo(o.task);
    }
}
